How Do I Have an Editor Depend on Another Property?
Sometimes the behavior of an editor might depend on the value a property other than the one being edited. For example:
- The editor needs to be enabled or disabled depending on the value of another property. For example, the ReticulationStyle property should be editable only if the IsSpline property is true.
- The possible values depend on the value of another property. For example, a Car might have Make and Model properties, and the set of permitted values for Model might depend on Make.
To access another property from a property editor data template, use the UnderlyingObject binding. For example:
CopyUsing UnderlyingObject
<DataTemplate x:Key="ReticulationStyleEditor"> <TextBox Text="{Binding Value}" IsEnabled="{Binding UnderlyingObject.IsSpline}" /> </DataTemplate> <DataTemplate x:Key="CarModelEditor"> <ComboBox SelectedValue="{Binding Value}" ItemsSource="{Binding UnderlyingObject.Make, Converter={StaticResource GetModelsFromMake}}" /> </DataTemplate>
Bindings to UnderlyingObject properties can be two-way, meaning you can create a single editor UI that modifies multiple properties. However you should be cautious about doing this because the “other” properties will still have entries in the property grid unless you hide them.